package py.com.sole.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import py.com.sole.dao.DaoFactory;

import py.com.sole.model.Materia;

@FacesConverter(value="materiaConverter")
public class MateriaConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		
		if(value==null||value.equals("")){
            return null;
        }
		
		Materia materia = new Materia();
		materia = DaoFactory.getMateria().getMateriaByName(value);
		return materia;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if(value==null){
            return null;
        }
		Materia materia = (Materia)value;
		return materia.getDescripcion();
	}

}
